//
//  TestTableViewCell.m
//  TestTableViewCellClick
//
//  Created by apple on 17/4/7.
//  Copyright © 2017年 wax. All rights reserved.
//

#import "TestTableViewCell.h"

@interface TestTableViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *myImageView;

//左侧按钮
@property (weak, nonatomic) IBOutlet UIButton *myBtn;

@end

@implementation TestTableViewCell



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    _showView.hidden = YES;
    
    _myImageView.userInteractionEnabled = YES;
  
}



+(instancetype)loadCell{

    return [[NSBundle mainBundle] loadNibNamed:@"TestTableViewCell" owner:nil options:nil].lastObject;
    
}


#pragma mark - setDatas

-(void)setIndexTag:(NSInteger)indexTag{

    _indexTag = indexTag;
    
    //当前点击的按钮
    [self settingBtnClick];
    
    //设置-Tap的点击事件
    [self settingTapClick];
  
}

#pragma mark - 设置按钮/手势的点击事件
-(void)settingBtnClick{
    
    NSLog(@"indexTag = %ld",(long)_indexTag);
    
    //此时给Btn下标赋值
    _myBtn.tag = _indexTag;
    
    //这里创建Btn的点击事件？
    [_myBtn addTarget:self action:@selector(clickmyBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    
}

-(void)clickmyBtn:(UIButton *)sender{
    
    //数据回传-下标
    NSString * cellClickNoti = @"cellClickIndexTagNoti";
    
    [[NSNotificationCenter defaultCenter]postNotificationName:cellClickNoti object:@(sender.tag)];
    
    _showView.hidden = !_showView.hidden;
    
    //发送通知，控制tableViewCell的点击事件
    NSString * testCellClickNoti = @"testCellClickNoti";
    
    [[NSNotificationCenter defaultCenter]postNotificationName:testCellClickNoti object:@(_showView.hidden)];
    
}


//点击imageView
-(void)settingTapClick{
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickImage:)];
    
    _myImageView.tag = _indexTag;
    
    [_myImageView addGestureRecognizer:tap];
}


-(void)clickImage:(UITapGestureRecognizer *)tap{
    
    //tap手势是没有tag的！！ 记得加一个view！
    NSInteger indexTag = tap.view.tag;
    
    NSLog(@"点击的是头像的->tag =%ld",(long)indexTag);
    
    NSString * cellClickNoti = @"cellClickIndexTagNoti";
    
    [[NSNotificationCenter defaultCenter]postNotificationName:cellClickNoti object:@(indexTag)];
    
    _showView.hidden = !_showView.hidden;
    
    //发送通知，控制tableViewCell的点击事件
    NSString * testCellClickNoti = @"testCellClickNoti";
    
    [[NSNotificationCenter defaultCenter]postNotificationName:testCellClickNoti object:@(_showView.hidden)];
    
    
}


#pragma mark - 点击按钮的（btn1,btn2）

- (IBAction)clickBtn1:(id)sender {
    
    NSLog(@"clickBtn1");
    
    NSInteger tag = 1;
    
    if ([self.delegate respondsToSelector:@selector(ApprovalIconPush:)]) {
        
        [self.delegate ApprovalIconPush:tag];
        
    }
    
}

- (IBAction)clickBtn2:(id)sender {
    NSLog(@"clickBtn2");

    NSInteger tag = 2;
    
    if ([self.delegate respondsToSelector:@selector(ApprovalIconPush:)]) {
        
        [self.delegate ApprovalIconPush:tag];
        
    }
}


@end
